package com.ruoyi.crm.moulds.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class CrmRabbitConfig {

    public static  final String CRM_QUEUE_CONTRACT_CRETED="crm_queue_contract_created";
    public static  final String CRM_EXCHANGE_CONTRACT="crm_exchange_contract";
    //路由key
    public static  final String CRM_ROUTING_KEY_CONTRACT_CREATED="crm.routing.key.contract.created";

    //队列
    @Bean
    public Queue crmContractCreatedQueue(){
        return new Queue(CRM_QUEUE_CONTRACT_CRETED);
    }

    //精确匹配 交换机
    @Bean
    public DirectExchange crmContractExchange(){
        return new DirectExchange(CRM_EXCHANGE_CONTRACT);
    }

    //使用路由将队列绑定到交换机
    @Bean
    public Binding crmContractBinding(Queue crmContractedQueue,DirectExchange crmContractDirectExchange){
        return BindingBuilder.bind(crmContractedQueue).to(crmContractDirectExchange).with(CRM_ROUTING_KEY_CONTRACT_CREATED);
    }
}
